<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  
  <head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" th:href="@{/pages/favicon.ico}" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/pages/css/font.css}" href="./css/font.css">
    <link rel="stylesheet" th:href="@{/pages/css/xadmin.css}" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" th:src="@{/pages/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/pages/js/xadmin.js}" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form"  th:action="@{/manage/article/add}" method="post">
          <div class="layui-form-item">
              <label for="title" class="layui-form-label">
                  <span class="x-red">*</span>标题
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="title" name="title" lay-verify="required" class="layui-input"/>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="type" class="layui-form-label">
                  <span class="x-red">*</span>类别
              </label>
              <div class="layui-input-inline">
                  <select id="type" name="type" lay-verify="required">
                      <option th:value="${articleType.code}" th:each="articleType:${articleTypes}" th:text="${articleType.name}"></option>
                  </select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="source" class="layui-form-label">
                  <span class="x-red">*</span>来源
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="source" id="source" lay-verify="required"  class="layui-input"/>
              </div>
          </div>
            <div class="layui-form-item">
                <label for="uploadPath" class="layui-form-label">
                    <span class="x-red">*</span>图片
                </label>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="uploadPath">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <div class="layui-form-item">
                    <img id="imgPath" />
                    <input type="hidden" name="imgPath"/>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    内容
                </label>
                <div class="layui-input-block">
                    <textarea  id="desc" name="content"  class="layui-textarea" >&emsp;&emsp;</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="add">增加</button>
            </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer','upload', 'layedit'], function(){
            $ = layui.jquery;

            var layedit = layui.layedit;
            layedit.build('desc', {
                hideTool: ['image']
            }); //建立编辑器

          var form = layui.form
          ,layer = layui.layer
            upload=layui.upload;
        
          //自定义验证规则
          form.verify({

          });

          //监听提交
          form.on('submit', function(data){
//            console.log(data.field);
          });

            upload.render({
                elem: '#uploadPath' //绑定元素
                ,url: '/manage/article/upload' //上传接口
                ,accept:'images'
                ,done: function(res){
                    //上传完毕回调
                    $("#imgPath").attr("src",res.imgPath);
                    $("input[name='imgPath']").val(res.imgPath);
                }
                ,error: function(){
                    //请求异常回调
                }
            });
          
        });
    </script>
  </body>

</html>